package com.huangmb.anymark.server.service.impl;

import com.huangmb.anymark.server.dao.BaseDao;
import com.huangmb.anymark.server.dao.UserDao;
import com.huangmb.anymark.server.model.User;
import com.huangmb.anymark.server.service.UserService;
import org.hibernate.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author hmb
 * @version 1.0
 * @since 2016/5/4 21:12
 */
@Service(value = "userService")
@Transactional
public class UserServiceImpl extends BaseServiceImpl<User> implements UserService {
    private static Logger log = LoggerFactory.getLogger(UserServiceImpl.class);
    @Resource(name = "userDao")
    private UserDao mUserDao;
    @Override
    @Resource(name = "userDao")
    public void setDao(BaseDao<User> dao) {
        super.setDao(dao);
    }

    @Override
    public User findByName(String name) {
    log.debug("find user by name:"+name);
        String hql = "from User where name=?";
        List<User> list = mUserDao.findByHQL(hql, name);

        return list == null || list.isEmpty() ? null : list.get(0);
    }
}
